import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {verifyService} from "../service/verify.component";
import {HttpService} from "../share/http.service";
import {url} from '../share/url';
import {flyIn} from "../animations/flyIn";

@Component({
  moduleId: module.id,
  selector: 'myLogin',
  templateUrl: 'login.component.html',
  providers: [verifyService],
  animations:[
    flyIn
  ]
})
export class loginComponent implements OnInit {
  public loginUrl:string = url.url+"/app1/login";
  public code:string;
  public codeUnique:string='';
  constructor(
    public heroService: verifyService,
    public router: Router,
    public http:HttpService
  ) {

  }

  model: {} = {};

  doLogin() {
    console.log(this.model);
    console.log(this.codeUnique);
    this.http.httpPost(this.loginUrl,this.model)
      .subscribe((res) =>{
      console.log(res);
        // if(this.code===this.codeUnique && res.code){
          if(res.code){
          this.router.navigate(['/index/main']);
        }else{
          alert('请检查输入内容')
        }
      });
  }

  ngOnInit() {
    let bbb = this.heroService.GVerify();
    // let code = this.heroService.getTextCode();
    let code = bbb({
      id: "verify", //容器Id
      canvasId: "verifyCanvas", //canvas的ID,可以不用设置
      width: "100", //canvas宽度
      height: "30", //canvas高度
      type: "number", //图形验证码默认类型blend:数字字母混合类型、number:纯数字、letter:纯字母
      code: ""
    });
    this.code =code;
  }
}
